<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @cancel="handleCancel"
    @ok="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-row :gutter="16">
          <a-col class="gutter-row" :span="12">
            <div class="gutter-box">
              <a-form-item label="文件名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <j-category-select v-decorator="[ 'docCategory']" pcode="0" placeholder="请选择分类"/>
              </a-form-item>
            </div>
          </a-col>

          <a-col class="gutter-row" :span="12">
            <div class="gutter-box">
              <a-form-item label="文件名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input v-decorator="[ 'docName', validatorRules.docName]" placeholder="请输入文件名称"></a-input>
              </a-form-item>
            </div>
          </a-col>
          <a-col class="gutter-row" :span="12">
            <div class="gutter-box">
              <a-form-item label="文件编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input v-decorator="[ 'docNo', validatorRules.docNo]" placeholder="请输入文件编号"></a-input>
              </a-form-item>
            </div>
          </a-col>
          <a-col class="gutter-row" :span="12">
            <div class="gutter-box">
              <a-form-item label="定制科室" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input v-decorator="[ 'dzDepartment', validatorRules.dzDepartment]" placeholder="请输入定制科室"></a-input>
              </a-form-item>
            </div>
          </a-col>
<!--          <a-col class="gutter-row" :span="12">-->
<!--            <div class="gutter-box">-->
<!--              <a-form-item label="文件大小" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
<!--                <a-input-number v-decorator="[ 'docSize', validatorRules.docSize]" placeholder="请输入文件大小" style="width: 100%"/>-->
<!--              </a-form-item>-->
<!--            </div>-->
<!--          </a-col>-->
          <a-col class="gutter-row" :span="12">
            <div class="gutter-box">
              <a-form-item label="三甲条款" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input v-decorator="[ 'jic', validatorRules.jic]" placeholder="请输入三甲条款"></a-input>
              </a-form-item>
            </div>
          </a-col>
          <a-col class="gutter-row" :span="12">
            <div class="gutter-box">
              <a-form-item label="生效日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <j-date placeholder="请选择生效日期" v-decorator="[ 'sxTime', validatorRules.sxTime]" :trigger-change="true" style="width: 100%"/>
              </a-form-item>
            </div>
          </a-col>
          <a-col class="gutter-row" :span="12">
            <div class="gutter-box">
              <a-form-item label="到期日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <j-date placeholder="请选择到期日期" v-decorator="[ 'dqTime', validatorRules.dqTime]" :trigger-change="true" style="width: 100%"/>
              </a-form-item>
            </div>
          </a-col>
          <a-col class="gutter-row" :span="12">
            <div class="gutter-box">
              <a-form-item label="三甲条款" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <j-dict-select-tag type="list" v-decorator="['isJic', validatorRules.isJic]" :trigger-change="true" dictCode="jic_status" placeholder="请选择三甲条款"/>
              </a-form-item>
            </div>
          </a-col>
          <a-col class="gutter-row" :span="12">
            <div class="gutter-box">
              <a-form-item label="能否下载" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <j-dict-select-tag type="list" v-decorator="['download', validatorRules.download]" :trigger-change="true" dictCode="download_status" placeholder="请选择能否下载"/>
              </a-form-item>
            </div>
          </a-col>
          <a-col class="gutter-row" :span="12">
            <div class="gutter-box">
              <a-form-item label="能否打印" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <j-dict-select-tag type="list" v-decorator="['print', validatorRules.print]" :trigger-change="true" dictCode="print_status" placeholder="请选择能否打印"/>
              </a-form-item>
            </div>
          </a-col>
          <a-col class="gutter-row" :span="12">
            <div class="gutter-box">
              <a-form-item label="审核人" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input v-decorator="[ 'audit', validatorRules.audit]" placeholder="请输入审核人"></a-input>
              </a-form-item>
            </div>
          </a-col>
<!--          <a-col class="gutter-row" :span="24">-->
<!--            <div class="gutter-box">-->
<!--              <a-form-item label="富文本" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
<!--                <j-editor v-decorator="['editor',{trigger:'input'}]"/>-->
<!--              </a-form-item>-->
<!--            </div>-->
<!--          </a-col>-->
          <a-col class="gutter-row" :span="12">
            <div class="gutter-box">
              <a-form-item label="文档状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <j-dict-select-tag type="list" v-decorator="['docStatus', validatorRules.docStatus]" :trigger-change="true" dictCode="doc_status" placeholder="请选择文档状态"/>
              </a-form-item>
            </div>
          </a-col>
          <a-col class="gutter-row" :span="12">
            <div class="gutter-box">
              <a-form-item label="是否过期" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <j-dict-select-tag type="list" v-decorator="['docExpired', validatorRules.docExpired]" :trigger-change="true" dictCode="doc_expired" placeholder="请选择是否过期"/>
              </a-form-item>
            </div>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import JCategorySelect from '@/components/jeecg/JCategorySelect'
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JDate from '@/components/jeecg/JDate'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"
  import JEditor from '@/components/jeecg/JEditor'

  export default {
    name: "DocModalCheck",
    components: {
      JDate,
      JDictSelectTag,
      JEditor,
      JCategorySelect
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          docCategory: {rules: [
              {required: true, message: '请输入文件分类!'},
            ]},
          docName: {rules: [
            ]},
          docNo: {rules: [
            ]},
          dzDepartment: {rules: [
            ]},
          docSize: {rules: [
            ]},
          jic: {rules: [
            ]},
          sxTime: {rules: [
            ]},
          dqTime: {rules: [
            ]},
          isJic: {rules: [
            ]},
          download: {rules: [
            ]},
          print: {rules: [
            ]},
          audit: {rules: [
            ]},
          editor: {rules: [
            ]},
          docStatus: {rules: [
            ]},
          docExpired: {rules: [
            ]},
        },
        url: {
          add: "/doc/doc/add",
          edit: "/doc/doc/edit",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'docCategory','docName','docNo','dzDepartment','docSize','jic','sxTime','dqTime','isJic','download','print','audit','editorString','docStatus','docExpired'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      //@ok="handleOk"
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
              method = 'put';
            }
            let formData = Object.assign(this.model, values);
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }

        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'docCategory','docName','docNo','dzDepartment','docSize','jic','sxTime','dqTime','isJic','download','print','audit','editorString','docStatus','docExpired'))
      },


    }
  }
</script>